package com.ch.d0415;

public class demo {
    public static  void main(String[] args){

        long time1 = System.currentTimeMillis();

        MyThread myThread = new MyThread();
        //启动线程
        myThread.start();

        Thread t = new Thread( new B() );
        t.start();
//        saodi();
//        sachuang();

        // 匿名类
        Thread t1 = new Thread(){
            public void run() {
                System.out.println("擦黑板");
            }
        };

        //lambada 表达式
        Thread t2 = new Thread( () -> {
            System.out.println("摆桌子");
            }
        );

        t1.start();
        t2.start();

        long time2 = System.currentTimeMillis();
        System.out.println(time2 - time1);

    }

    public static void saodi() throws InterruptedException {
        System.out.println("扫地");
        Thread.sleep(1000);
    }

    public static void sachuang() throws InterruptedException {
        System.out.println("擦窗");
        //让当前线程进入到休眠状态，单位毫秒
        Thread.sleep(2000);
    }
}

//继承Thread方式
class MyThread extends Thread {

    public void run() {
        try {
            demo.saodi();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class A {

}

//实现接口方式
class B extends A implements Runnable{

    @Override
    public void run() {
        try {
            demo.sachuang();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
